﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.Dto.ProSorce;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.deepprocessing
{
    public class DeepprocessHTMLHandler : IRequestHandler<DeepprocessHTMLCommond, Rulst>
    {



        private readonly IbaseRpository<ProcessMess> _ProcessMess;
        private
            readonly IbaseRpository<ProductionPutImages> _ProductionPutImages;
public DeepprocessHTMLHandler(IbaseRpository<ProcessMess> processMess, IbaseRpository<ProductionPutImages> productionPutImages)
        {
            _ProcessMess = processMess;
            _ProductionPutImages = productionPutImages;
        }

        public async Task<Rulst> Handle(DeepprocessHTMLCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };


            var list = (from a in _ProcessMess.Query()
                      where a.ProDuctionBasicid == request.ProDuctionBasicid
                       select new DeepprocessHTMLDto()
                       {
                           BossImages=new List<BossImages>(),
                           BossImagesthrre=new List<BossImagesthrre>(),
                           BossImagestwo=new List<BossImagestwo>(),
                           ProcessBossName=a.ProcessBossName,
                           Processclass=a.Processclass
                           ,Processlicence=a.Processlicence
                           ,ProcessLot=a.ProcessLot
                           ,ProcessPersonincharge=a.ProcessPersonincharge



                       }).FirstOrDefault();
            if(list!=null)
            {



                list.BossImages=_ProductionPutImages.Query().Where(x=>x.ProDuctionBasicid==request.ProDuctionBasicid&&x.Stypeid== Typenum.食品安全).Select(x=>new BossImages(){
                    images=x.PutImages,

                   
                }).ToList();


                list.BossImagesthrre = _ProductionPutImages.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid && x.Stypeid == Typenum.食品安全照片).Select(x => new BossImagesthrre()
                {
                    images = x.PutImages,


                }).ToList();
                list.BossImagestwo = _ProductionPutImages.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid && x.Stypeid == Typenum.加工企业).Select(x => new BossImagestwo()
                {
                    images = x.PutImages,


                }).ToList();


            }
            else
            {
                list=new DeepprocessHTMLDto();    
            }


            query.data = list;

            return query;


        }
    }
}
